/*
 * Copyright (c) Jack魏 2024 - 2024, All Rights Reserved.
 */

package cn.jackwei.yiyi.controller.view.sys;

import cn.jackwei.yiyi.pojo.bean.SysPage;
import cn.jackwei.yiyi.service.sys.SysPageService;
import cn.jackwei.yiyi.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 系统页面管理
 *
 * @author Jack魏
 * @since 2024/04/12 22:29
 */
@Controller
@RequestMapping("/sys")
public class SysPageView {
    @Autowired
    private SysPageService sysPageService;

    /**
     * 页面管理
     *
     * @return 管理页面
     */
    @GetMapping("pageView")
    public String pageView(Model model) {
        Result<List<SysPage>> listResult = sysPageService.listPageTree();
        model.addAttribute("pageList", listResult.getData());
        return "sys/pageView";
    }

    /**
     * 编辑页面表页面
     *
     * @return 编辑页面
     */
    @GetMapping("/sysPageEditView")
    public String sysPageEditView(Integer id, Integer parentId, Model model) {
        if (id != null) {
            SysPage page = sysPageService.getById(id);
            model.addAttribute("page", page);
        }
        model.addAttribute("parentId", parentId);
        return "sys/pageEditView";
    }

}
